package com.malljelly.study.config;

/**
 * Created by 骑着蜗牛去旅行 on 2018/8/12.
 */
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ProducerConfig {
    public static final String EXCHANGE = "com.malljelly.study.exchange"; // 交换空间名称
    public static final String ROUTINGKEY = "com.malljelly.study.routingkey"; // 设置路由key
    public static final String QUEUE_NAME = "com.malljelly.study.queue"; // 队列名称


    /**
     * 交换机和队列进行绑定
     * @param exchange
     * @param queue
     * @return
     */
    @Bean
    public Binding bindingExchangeQueue(DirectExchange exchange,Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY) ;
    }

    @Bean
    public DirectExchange getDirectExchange() { // 使用直连的模式
        return new DirectExchange(EXCHANGE, true, true);
    }


    @Bean
    public Queue queue() { // 要穿件的队列信息
        return new Queue(QUEUE_NAME);
    }
}
